import React from 'react';
import ReactDOM from 'react-dom';
import { Link } from 'react-router';
import { Breadcrumb, Button, Form, Input, Table, Row, Col,Select  } from 'antd';
const FormItem = Form.Item;
const Option = Select.Option;

const Demo = React.createClass({

  contextTypes: {
    router: React.PropTypes.object
  },

  getInitialState() {
    return {
      item: '意向房源',
      its: '列表',
      recoverTxt: '房源回收站',

    }
  },

  handleRouter() {
    let path = this.props.location.pathname;
    let lastPath = path.split('/')[path.split('/').length - 1];
    // console.log(lastPath)
    let index = '/landlord/rentBeforeIndex';
    let add = '/landlord/rentBeforeIndex/add';
    let goPathUrl = ( lastPath == 'list' || lastPath == 'rentBeforeIndex') ? add : index;
    this.context.router.push(goPathUrl);
  },

  handleClick(){
    let goPathUrl = '/landlord/rentBeforeIndex/recover';
    this.context.router.push(goPathUrl);
  },

  render() {
    let path = this.props.location.pathname;
    let lastPath = path.split('/')[path.split('/').length - 1];
    let routerItem = {
      'list': '列表',
      'rentBeforeIndex': '列表',
      'add': '添加意向房源',
      'recover': '回收站',
      'update': '修改',
    };
    console.log(lastPath);
    let txtName = ( lastPath == 'list' || lastPath == 'rentBeforeIndex') ? '添加意向房源' : '返回';

    return (
      <div>
        <div className="nav-bar">
          <Breadcrumb separator="-">
            <Breadcrumb.Item>{this.state.item}</Breadcrumb.Item>
            <Breadcrumb.Item>{routerItem[lastPath]}</Breadcrumb.Item>
          </Breadcrumb>
          { lastPath == 'list' || lastPath == 'rentBeforeIndex' ?
            <Button id="recover" className="ant-button recover-button" type="primary" htmlType="button"
                    onClick={this.handleClick}>{this.state.recoverTxt}</Button> : null
          }
          <Button id="add" className="ant-button add-button" type="primary" htmlType="button"
                  onClick={this.handleRouter}>{txtName}</Button>
        </div>
        <div className="content-wrapper">
          {this.props.children}
        </div>

      </div>

    );
  }
});

export default Demo